package com.dianrui.agent.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;


import com.dianrui.agent.R;
import com.dianrui.agent.util.GlideUtil;
import com.dianrui.agent.view.ninegride.NineView;
import com.dianrui.agent.view.ninegride.RatioImageView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 故障详情
 */
public class FaultDetailsActivity extends BaseActivity implements NineView.NineViewShowCallBack {
    private String orderCodes,numbers,title,contents, createTime, updateTimes;
    private List<String> imageList = new ArrayList<>();
    private List<String> imgList;

    @BindView(R.id.title)
    TextView titles;
    @BindView(R.id.order_code)
    TextView orderCode;
    @BindView(R.id.number)
    TextView number;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.remark)
    TextView remark;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.update_time)
    TextView updateTime;

    private ProgressDialog pd;
    @BindView(R.id.nine)
    NineView nine;

    @Override
    public int getContentViewId() {
        return R.layout.activity_fault_details;
    }

    @Override
    public void initView() {
        pd=new ProgressDialog(this);
        titles.setText("故障详情");
        nine.maxCount(9).spacing(3).setNineViewShowCallBack(this).setUrlList(imageList);
        if (getIntent() != null && getIntent().getExtras()!=null) {
            orderCodes=getIntent().getStringExtra("order_code");
            numbers=getIntent().getStringExtra("number");
            title=getIntent().getStringExtra("title");
            contents=getIntent().getStringExtra("contents");
             createTime=getIntent().getStringExtra("create_time");
             updateTimes=getIntent().getStringExtra("update_time");
            imgList = (List<String>) getIntent().getExtras().getSerializable("photo");
        }
        orderCode.setText(orderCodes);
        number.setText(numbers);
        name.setText(title);
        remark.setText(contents);
        time.setText( createTime);
        updateTime.setText( updateTimes);
        nine.setUrlList(imgList);
    }




    @OnClick({R.id.back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            default:
                break;
        }
    }


    @Override
    public void onDisplayOneImage(RatioImageView imageView, String url, int parentWidth, Context context) {
        if ("default".equals(url)) {
        } else {
            imageView.setTag(R.id.glide_tag, url);
            addImageViewList(GlideUtil.downLoader(false, imageView, FaultDetailsActivity.this));
        }
    }

    @Override
    public void onDisplayImage(RatioImageView imageView, RatioImageView closeButton, String url, int parentWidth, Context context) {
        if ("default".equals(url)) {
        } else {
            imageView.setTag(R.id.glide_tag, url);
            addImageViewList(GlideUtil.downLoader(false, imageView, FaultDetailsActivity.this));
        }
    }

    @Override
    public void onClickImage(int position, String url, List<String> urlList, Context context) {
        List<String> temp = new ArrayList<>();
        int count = 0;
        for (int i = 0; i < imgList.size(); i++) {
            if (!"default".equals(imgList.get(i))) {
                temp.add(imgList.get(i));
            } else {
                count++;
            }
        }
        startActivity(new Intent(FaultDetailsActivity.this, BigImageActivity.class)
                .putStringArrayListExtra("data", (ArrayList<String>) temp)
                .putExtra("current", position));
    }

    @Override
    public void onClickImageColse(int position, String url, List<String> urlList, Context context) {

    }

    @Override
    public void onSamePhotos(List<String> mRejectUrlList) {

    }
}
